package com.ruoyi.common.config.restTemplate;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.web.client.RestTemplateBuilder;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.converter.StringHttpMessageConverter;
import org.springframework.web.client.RestTemplate;

import java.nio.charset.StandardCharsets;

/**
 * @version 1.0
 * @ClassName
 * @Author DELL
 * @Date 2020/6/28 16:58
 **/
@Configuration
public class RestTemplateConfig {

    @Autowired
    private RestTemplateBuilder restTemplateBuilder;

    /**
     * springboot  集成restTemplate  发送http请求
     *
     * @return
     */
    @Bean
    public RestTemplate restTemplate(){
        RestTemplate restTemplate = restTemplateBuilder.build();
        restTemplate.getMessageConverters().
                set(1, new StringHttpMessageConverter(StandardCharsets.UTF_8));
        return restTemplate;
    }
}
